#include<bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
    int n,a[20005];
    cin >> n;
    for(int i = 0;i < n;i ++){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0;i < (2<<n);i ++){
        int j = i;
        int cnt = 0;
        int b[20005] = {0};
        for(int k = 0;k < n;k ++){
            b[k] = j % 2;
            j /= 2;
        }
        for(int p = 0;p < n;p++){
            for(int o = p-1;o >= 0;o --){
                if(b[o] == b[p]){
                    if(a[o] == a[p]){
                        cnt += a[o];
                    }
                    break;
                }
            }
        }
        ans = max(ans,cnt);
    }
    cout << ans << endl;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin >> t;
    while(t --){
        solve();
    }
    return 0;
}
